var scrapVm = new Vue({
	el:'#equip-scrap-content',
	data: function() {
		return {
			equipmentid: '',
			reason: '',
			reasonError: ''
		}
	},
	mounted: function() {
		var self = this;
		mui.init();
		mui.plusReady(function () {
			var lastPage = plus.webview.getWebviewById('change');
			if(lastPage) lastPage.close();
			self.initValidator();
		})
	},
	methods:{
		initValidator: function() {
			this.constraints = {
				reason: {
					length: {
						maximum: 60,
						message: "长度不能超过60"
					}
				}
			}
		},
		hitchTypePicker: function() {
			var self = this;
			var picker = new mui.PopPicker();
			picker.setData([{value:'软件',text:'软件'},{value:'硬件',text:'硬件'},{value:'网络',text:'网络'}]);
			picker.show(function (selectItems) {
				self.hitchType = selectItems[0].text;
			})
		},
		submitScrap: function() {
			var self = this;
			var data = {};
			if(this.reason) {
				data['reason'] = this.reason;
			}
			var errors = validate(data, this.constraints);
			
			if(errors) {
				if(errors.reason) {
					this.reasonError = errors.reason;
				}
			} else {
				mui.confirm('该操作不可撤销,确认报废该设备? ','提示',['取消','确认'],function (e) {
					if(e.index == 1){
						self.submitData();
					}
				},'div')
			}
		},
		submitData: function() {
			var self = this;
			var url = config.requestBaseUrl + 'scrapEquip';
			var recorderid = plus.storage.getItem('userid');
			
			var thisPage = plus.webview.currentWebview();
			this.equipmentid = thisPage.equipmentid;
			
			console.log(this.equipmentid)
			mui.ajax(url,{
				data:{
					equipmentid: this.equipmentid,
					reason: this.reason,
					recorderid: recorderid
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					mui.toast(data.msg);
					if(data.isSuccess) {
						thisPage.close();
						var changePage = plus.webview.getWebviewById('change');
						if(changePage) changePage.close();
					}
				},
				error:function(xhr,type,errorThrown){
					console.log('失败' + errorThrown)
					mui.toast("出错!请重试或联系管理员");
				}
			});
		}
	}
})